module.exports = (sequelize, DataTypes) => {
    const Content = sequelize.define(
        'Content',
        {
            id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                autoIncrement: true,
                primaryKey: true
            },
            content: {
                type: DataTypes.STRING,
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '交接内容不能为空'
                    }
                },
                comment: '交接内容'
            },
            handover_id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                references: {
                    model: 'Handover',
                    key: 'id'
                },
                validate: {
                    notNull: {
                        msg: '交接条目不能为空'
                    }
                },
                comment: '所属交接的ID'
            }
        },
        {
            tableName: 'content'
        }
    )

    Content.associate = function(models) {
        models.Content.belongsTo(models.Handover, { foreignKey: 'handover_id', targetKey: 'id' })
    }

    return Content
}
